package org.zjvis.datascience.web.api;

import cn.weiguangfu.swagger2.plus.annotation.ApiPlus;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.mayabot.nlp.fasttext.FastText;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.zjvis.datascience.common.model.ApiResult;
import org.zjvis.datascience.service.AutoJoinService;
import org.zjvis.datascience.service.FastTextService;

@ApiPlus(value = true)
@RestController
@RequestMapping("/autoJoinApi/")
@Api(tags = "autoJoinApi", description = "auto join插件接口")
@Validated
public class AutoJoinApi {
    @Autowired
    private AutoJoinService autoJoinService;

    @Autowired
    private FastTextService fastTextService;

    @PostMapping(value = "/autoJoinRecommend")
    @Transactional
    @ResponseBody
    @ApiOperation(value = "autoJoinRecommend", notes = "autoJoinRecommend")
    public ApiResult<JSONArray> autoJoinRecommend(@RequestBody JSONObject params) {
        String leftTableName = params.getString("leftTableName");
        String rightTableName = params.getString("rightTableName");
        JSONObject leftSemantics = params.getJSONObject("leftSemantics");
        JSONObject rightSemantics = params.getJSONObject("rightSemantics");
        FastText model = fastTextService.getAutojoinModel();
        JSONArray ret = autoJoinService.autoJoinRecommend(leftTableName, rightTableName, leftSemantics, rightSemantics, model);
        return ApiResult.valueOf(ret);
    }
}
